"""
按周期计算是否新高新低，简单方法
"""
class isnhnl_bybar:
    def __init__(self,timeperiod=10):
        self.timeperiod=timeperiod
        self.data=[[],[]]
        self.timekey = None
    def oncalc(self,b,timekey=None):
        rst=None
        if b is not None:
            timekey=b["timekey"]
            high=b["high"]
            low=b["low"]
            if timekey   is not None:
                if timekey == self.timekey:
                    self.data[0][-1] = high
                    self.data[1][-1] = low
                else:
                    self.data[0].append(high)
                    self.data[1].append(low)
                    self.timekey = timekey
            else:
                self.data[0].append(high)
                self.data[1].append(low)
            if len(self.data[0])>self.timeperiod:
                self.data[0].pop(0)
                self.data[1].pop(0)
            if len(self.data[0])==self.timeperiod:
                if max(self.data[0])==high:
                    rst=1
                elif min(self.data[1])==low:
                    rst=-1
                else:
                    rst=0
        return rst